package com.hr.controller;

import com.hr.pojo.HrUserInfo;
import com.hr.pojo.HrUserInfoExample;
import com.hr.service.impl.UserServiceImpl;
import com.hr.service.impl.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * 首页跳转页面
 */
@Controller
public class PageController {

    private UserService userService = new UserServiceImpl();

    @RequestMapping("/")
    public String index(HttpServletRequest request) {
        HttpSession session = request.getSession();
        HrUserInfoExample userInfoExample = new HrUserInfoExample();
        if (session != null) {
            String username = session.getAttribute("username")==null ?"":session.getAttribute("username").toString() ;
            String password = session.getAttribute("password")==null ?"":session.getAttribute("password").toString() ;
            HrUserInfo hrUserInfo = null;
            if (username != "") {
                HrUserInfoExample.Criteria criteria = userInfoExample.createCriteria();
                criteria.andUsernameEqualTo(username);
                criteria.andPasswordEqualTo(password);
                hrUserInfo = userService.selectByExample(userInfoExample).get(0);
                if (hrUserInfo != null) {
                    return "manager";
                }
            }
        }
        return "login";
    }
}